home *** CD-ROM | disk | FTP | other *** search
- /* STDWIN -- SYTEM WINDOW. */
-
- #include "alfa.h"
-
- WINDOW *syswin; /* Window id 0, the system window */
- /* Global because wgetevent needs to know about
- it, so it can suppress events belonging to
- this window. */
-
- static void
- helpmessage()
- {
- char buf[256];
- char shortcut[256];
-
- getbindings(shortcut, 0, MENU_CALL);
- sprintf(buf, "[Use %s to get a menu of commands]", shortcut);
- wmessage(buf);
- }
-
- void
- initsyswin()
- {
- syswin= wopen("System", wsysdraw);
- helpmessage();
- }
-
- char *sysmsg; /* Message to be drawn at (0, 0) */
- TEXTEDIT *syste; /* Textedit record to be drawn, too */
-
- /*ARGSUSED*/
- static void
- wsysdraw(win, left, top, right, bottom)
- WINDOW *win;
- int left, top;
- int right, bottom;
- {
- if (sysmsg != NULL) {
- (void) wdrawtext(0, 0, sysmsg, -1);
- if (syste != NULL)
- tedraw(syste);
- }
- else
- drawmenubar();
- }
-
- void
- menubarchanged()
- {
- uptodate[0]= FALSE;
- }
-
- /* Print a message in the system window.
- If the message is non-null, the screen is updated immediately. */
-
- void
- wmessage(str)
- char *str;
- {
- if (sysmsg != NULL)
- free(sysmsg);
- sysmsg= strdup(str);
- if (syste != NULL) {
- tefree(syste);
- syste= NULL;
- }
- wchange(syswin, 0, 0, 9999, 9999);
- wnocaret(syswin);
- if (str != NULL) {
- wupdate(syswin);
- wflush();
- }
- }
-
- /* Ask for an input string. */
-
- bool
- waskstr(prompt, buf, len)
- char *prompt;
- char *buf;
- int len;
- {
- WINDOW *savewin= front;
- WINDOW *win= syswin;
- bool ok= FALSE;
- bool stop= FALSE;
- int teleft;
-
- wsetactive(win);
- wmessage((char *) NULL);
- sysmsg= prompt;
- teleft= wtextwidth(prompt, -1) + wtextwidth(" ", 1);
- if (teleft > columns * 3/4)
- teleft= columns * 3/4;
- syste= tealloc(syswin, teleft, 0, columns-teleft);
- tereplace(syste, buf);
- tesetfocus(syste, 0, 9999);
- do {
- EVENT e;
-
- if (!wsysevent(&e, FALSE)) {
- wupdate(syswin);
- wflush();
- wsysevent(&e, TRUE);
- }
- e.window= syswin; /* Not filled in by wsys*event();
- needed by teevent(). */
-
- switch (e.type) {
-
- case WE_MENU:
- if (e.u.m.id != 0) {
- wfleep();
- break;
- }
- switch (e.u.m.item) {
-
- case SUSPEND_PROC:
- _wsuspend();
- break;
-
- case REDRAW_SCREEN:
- _wredraw();
- break;
-
- case LITERAL_NEXT:
- _wlitnext(&e);
- goto char_case;
-
- default:
- if (e.u.m.item >= FIRST_CMD &&
- e.u.m.item <= LAST_CMD)
- wsyscommand(&e);
- break;
- }
- if (e.type != WE_COMMAND)
- break;
-
- /* Fall through from previous case! */
- case WE_COMMAND:
- switch (e.u.command) {
-
- case WC_RETURN:
- case WC_CANCEL:
- ok= e.u.command == WC_RETURN;
- stop= TRUE;
- break;
-
- default:
- if (!teevent(syste, &e))
- wfleep();
- break;
-
- }
- break;
-
- char_case: /* Jump here from LITERAL_NEXT menu case */
- case WE_CHAR:
- case WE_MOUSE_DOWN:
- case WE_MOUSE_MOVE:
- case WE_MOUSE_UP:
- if (!teevent(syste, &e))
- wfleep();
- break;
-
- }
- } while (!stop);
- if (ok) {
- strncpy(buf, tegettext(syste), (size_t)len);
- buf[len-1]= EOS;
- }
- sysmsg= NULL;
- wmessage((char *) NULL);
- wsetactive(savewin);
- return ok;
- }
-